/// 匿名函数 study
//匿名函数。匿名函数有一个关联的环境被称为“闭包函数”，
fn anonymous_test() {
    let a1 = |x, y, z| x + y - z;
    assert_eq!(a1(1, 3, 1), 3);

    let b1 = |x| {
        let mut s: i32 = x;
        s += 9;
        s
    };
    assert_eq!(4, b1(2));
}

/// 向量 vec![] study
//一个‘向量’是一个动态的或者‘可增长的’数组，作为标准库类型 Vec<T>来实现。
pub fn vec_test() {
    // defined method 1
    let _ = vec![1, 2, 3, 4, 5]; // v: Vec<i32>
    // defined method 2:重复一个初始值：
    let _ = vec![0; 10]; // ten zeroes
    //访问元素1
    let v = vec![1, 2, 3, 4, 5];
    println!("The third element of v is {}", v[2]); // is 3

    //访问元素2
    let a: Option<&i32> = v.get(3);
    match a {
        Some(n) => println!("Fourth element of a vector is {}", n),
        None => println!("None"),
    }

    //循环访问
    // for i in &v {
    for (i1, v1) in v.iter().enumerate() {
        println!("A reference to {},{}", i1, v1);//  1 | 2 | 3 | 4 | 5
    }
}


// println!("{}", add_test(1,3))
fn add_test(a: i32, b: i32) -> i32 {
    a + b
}
